/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-07-16
 * Time: 19:21
 */
public class Test {
    public ListNode Merge (ListNode pHead1, ListNode pHead2) {
        if (pHead1 == null && pHead2 == null) {
            return null;
        }
        if (pHead1 != null && pHead2 == null) {
            return pHead1;
        }
        if (pHead2 != null && pHead1 == null) {
            return pHead2;
        }
        ListNode newHead = new ListNode(-1);
        ListNode tmp = newHead;
        while (pHead1 != null && pHead2 != null) {
            if (pHead1.val < pHead2.val) {
                tmp.next = pHead1;
                pHead1 = pHead1.next;
                tmp = tmp.next;
            } else {
                tmp.next = pHead2;
                pHead2 = pHead2.next;
                tmp = tmp.next;
            }
        }
        if (pHead1 != null) {
            tmp.next = pHead1;
        }
        if (pHead2 != null) {
            tmp.next = pHead2;
        }
        return newHead.next;
    }}
